#include "hotkeybar.h"

HotKeyBar::HotKeyBar(QWidget *parent) : QLineEdit(parent)
{
    this->mKeymod=Qt::ControlModifier;
    this->mKeyval=Qt::Key_F1;
    this->setFocusPolicy(Qt::FocusPolicy(Qt::TabFocus|Qt::ClickFocus));
    this->setStyleSheet("QLineEdit{border:2px solid rgb(240, 240, 240);}");
}

void HotKeyBar::setHotKey(Qt::Key key, Qt::KeyboardModifiers mode)
{
    this->mKeyval=key;
    this->mKeymod=mode;
    this->setShowText(key,mode);
}

void HotKeyBar::setKeyString(KeyString *pKeyString)
{
    this->mpKeystring=pKeyString;
}

void HotKeyBar::setShowText(Qt::Key key, Qt::KeyboardModifiers mode)
{
    QString showText=this->mpKeystring->key2String(key, mode);
    this->setText(showText);
}

void HotKeyBar::focusInEvent(QFocusEvent *e)
{
    QLineEdit::focusInEvent(e);
    this->setStyleSheet("QLineEdit{border:2px solid rgb(163, 219, 144);}");
}

void HotKeyBar::focusOutEvent(QFocusEvent *e)
{
    QLineEdit::focusOutEvent(e);
    this->setStyleSheet("QLineEdit{border:2px solid rgb(240, 240, 240);}");
}

void HotKeyBar::keyPressEvent(QKeyEvent *event)
{
    this->mKeymod=event->modifiers();
    this->mKeyval=Qt::Key(event->key());

    this->sgn_hotKeyChanged(this->mKeyval,this->mKeymod);
    this->setShowText(this->mKeyval,this->mKeymod);
}
